{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 下面代码是测试DS18B20温度传感器和数码管\n",
    "##注：本段代码，复制自：https://github.com/spoonysonny/SAKS-tutorials/tree/master/temperature-display-ds18b20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#34.8\n",
      "#34.8\n",
      "#34.8\n",
      "#34.8\n",
      "#34.8\n",
      "#34.8\n",
      "#34.8\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.8\n",
      "#34.8\n",
      "#34.8\n",
      "#34.9\n",
      "#34.9\n",
      "#34.8\n",
      "#34.8\n",
      "#34.7\n",
      "#34.6\n",
      "#34.6\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.5\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.4\n",
      "#34.5\n",
      "#34.6\n",
      "#34.6\n",
      "#34.6\n",
      "#34.6\n",
      "#34.8\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.9\n",
      "#34.8\n",
      "程序终止\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/env python\n",
    "# -*- coding: utf-8 -*-\n",
    "#\n",
    "# Copyright (c) 2015 NXEZ.COM.\n",
    "# http://www.nxez.com\n",
    "#\n",
    "# Licensed under the GNU General Public License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "#   http://www.gnu.org/licenses/gpl-2.0.html\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License.\n",
    "# tutorials url: http://shumeipai.nxez.com/2015/10/11/saks-diy-tutorials-temperature-display-ds18b20.html\n",
    "\n",
    "__author__ = 'Spoony'\n",
    "__license__  = 'Copyright (c) 2015 NXEZ.COM'\n",
    "\n",
    "from sakshat import SAKSHAT\n",
    "import time\n",
    "\n",
    "#Declare the SAKS Board\n",
    "SAKS = SAKSHAT()\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        while True:\n",
    "            #从 ds18b20 读取温度（摄氏度为单位）\n",
    "            temp = SAKS.ds18b20.temperature\n",
    "            #返回值为 -128.0 表示读取失败\n",
    "            if temp == -128.0 :\n",
    "                #10秒后再次尝试\n",
    "                time.sleep(10)\n",
    "                continue\n",
    "\n",
    "            print ((\"%5.1f\" % temp).replace(' ','#'))\n",
    "            #数码管显示温度数值，5位(含小数点)、精确到小数点1后1位\n",
    "            SAKS.digital_display.show((\"%5.1f\" % temp).replace(' ','#'))\n",
    "            time.sleep(1)\n",
    "        input(\"Enter any keys to exit...\")\n",
    "    except KeyboardInterrupt:\n",
    "        print (\"程序终止\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
